package test.iso
{
	import flash.display.Sprite;
	import flash.ui.Keyboard;
	
	import level4.display.GameDispose;
	import level4.engines.GameEngine;
	import level4.input.KeyState;
	import level4.input.Keys;
	import level4.interfaces.IGameComponent;
	import level4.iso.DrawnIsoBox;
	import level4.iso.DrawnIsoTile;
	import level4.iso.IsoWorld;
	import level4.iso.Point3D;

	public class IsoWorldTest extends GameDispose implements IGameComponent
	{
		private var world:IsoWorld;
		public function IsoWorldTest()
		{
			world = new IsoWorld();
			addChild(world);
			setupTiles();
			setupBox();
			
			GameEngine.addComponent(this);
		}
		private function setupTiles():void{
			for(var i:int = 0;i<20;i++){
				for(var j:int = 0;j<20;j++){
					var tile:DrawnIsoTile = new DrawnIsoTile(20,0xcccccc,20)
						
					var pt3d:Point3D = new Point3D(i * 20,0,j * 20);
						tile.IsoPoint = pt3d;
						world.addChildToFloor(tile);
						GameEngine.addComponent(tile)
				}
			}
		}
		private var box:DrawnIsoBox;
		private function setupBox():void{
			box = new DrawnIsoBox(20,0xff0000,20);
			box.IsoPoint = new Point3D(10*20,0,5*20);
			world.addChildToWorld(box);
			GameEngine.addComponent(box);
		}
		
		public function update(timeDiff:Number):void{
			box.stopMove();
			if(KeyState.isKeyDown(Keyboard.LEFT)){
				box.Vx = -.5;
			}
			if(KeyState.isKeyDown(Keyboard.RIGHT)){
				box.Vx = .5;
			}
			if(KeyState.isKeyDown(Keyboard.UP)){
				box.Vz = -.5;
			}
			if(KeyState.isKeyDown(Keyboard.DOWN)){
				box.Vz = .5;
			}
			box.move();
		}
		
	}
}